/**
 * 达人文章
 * @author Jim
 * @date 2020/02/04
 * @update 2020/02/04
 */
import React, {Component} from 'react';
import {ScrollView, View, StyleSheet, Text} from 'react-native';
import Header from '../../components/Header';
import Axios from 'axios';
import WebView from 'react-native-webview';
import Navigation from '../../utils/Navigation';
import {IsNullObject} from '../../utils/utils';
import HTMLView from 'react-native-htmlview';

const default_state = {
  loading: false,
  data: {},
};

export default class Article extends Component {
  constructor(props) {
    super(props);
    this.state = default_state;
  }

  componentDidMount() {
    this.GetData();
  }

  /**
   * 获取数据
   */
  GetData() {
    const {id} = this.props.navigation.state.params;

    // 11922
    console.log(
      'http://v2.api.haodanku.com/talent_article/apikey/mxclub/id/11922',
    );
    Axios.get(
      `http://v2.api.haodanku.com/talent_article/apikey/mxclub/id/${id}/`,
    ).then((res) => {
      this.setState({
        data: res.data.data,
      });
    });
  }
  render() {
    const {id} = this.props.navigation.state.params;
    const {data} = this.state;
    const temp = '';
    return (
      <>
        <Header title={'达人文章'} />
        {/*<Text onPress={() => {*/}
        {/*this.refs.webview.postMessage(this.encodeHtml(data.article));*/}
        {/*}}>发送数据到WebView</Text>*/}
        {IsNullObject(data.article) === true ? (
          <View />
        ) : (
          <WebView
            ref={'webview'}
            style={{flex: 1}}
            originWhitelist={['*']}
            source={{
              uri: ` https://www.haodanku.com/talent/article_page/id/${id}`,
            }}
            mixedContentMode="always"
            onMessage={(event) => {
              Navigation.navigate('DetailIndex', {id: event.nativeEvent.data});
            }}
          />
        )}
      </>
    );
  }
}
